'''
Created on Nov 28, 2012

@author: shraybansal
'''
from utils import readAllPickles
from utils import modGests
import math
import os

def changeToRadian(gestSet):
    for gesKey in gestSet.keys():
        """Get X,Y,Z ang vels in degrees"""
        xDeg = gestSet[gesKey].returngX()
        yDeg = gestSet[gesKey].returngY()
        zDeg = gestSet[gesKey].returngZ()
        
        """Convert to Radians"""
        xRad = [[j*math.pi/180 for j in i] for i in xDeg] 
        yRad = [[j*math.pi/180 for j in i] for i in yDeg] 
        zRad = [[j*math.pi/180 for j in i] for i in zDeg] 
        
        """Now replace with new radian values in Gesture feature"""
        gestSet[gesKey].setAngVel(xRad, yRad, zRad)


def getStartAcc(keys):
    work_dir = os.getcwd()
    path = work_dir+'/StartAcc//'
    filename='startAcc.txt'
    f = open(path+filename, 'r')
    read = f.readlines()
    f.close()
    
    startAcc = {}
    
    for key in keys:
        startAcc[key]=[]

    cur_key = None
    
    
    for line in read:
        line  = line.strip()
        if not line=='':
            words = line.split()
            if(len(words)==1 and words[0].lower() in [key.lower() for key in keys]):
                for key in keys:
                    if key.lower()==words[0].lower():
                        cur_key = key
            elif(len(words)==3):
                startAcc[cur_key].append([float(word) for word in words])
            
            
    return startAcc

if __name__=='__main__':
    gestSet = readAllPickles()
    changeToRadian(gestSet)
    startAcc = getStartAcc(gestSet.keys())
#    print startAcc['Door_Open']
    
#    print '-----Number of start accelerations read per gesture'
    for gesKey in gestSet.keys():
#        print gesKey, ' ', len(startAcc[gesKey]), len(gestSet[gesKey].returngX()),'in pickle'
        if not (len(startAcc[gesKey])==len(gestSet[gesKey].returngX())):
            print gesKey,'DONOT MATCH'
            print gesKey, ' ', len(startAcc[gesKey]), len(gestSet[gesKey].returngX()),'in pickle'
            for strt_vec in startAcc[gesKey]:
                print strt_vec

    """Write modified pickles"""
    modGests(gestSet, startAcc)

    